<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="统计时间">
          <el-date-picker
            v-model="form.time"
            type="year"
            value-format="yyyy"
            placeholder="选择年"
            :clearable="false"
          >
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="统计时间">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            :clearable="false"
          >
          </el-date-picker>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="sumBox">销售总金额：{{ sum }}元</div>
    <div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        border
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          prop="id"
          width="70"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="name" align="center" label="项目名称">
        </el-table-column>
        <el-table-column prop="count" align="center" label="订单总数量">
        </el-table-column>
        <el-table-column prop="amount" align="center" label="订单总金额">
        </el-table-column>
        <!-- <el-table-column align="center" label="水票图片">
          <template slot-scope="scope">
            <el-image
              style="width: 80px; height: 80px"
              :src="scope.row.water_img"
              fit="cover"
            ></el-image>
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="statis_time" align="center" label="统计时间">
        </el-table-column> -->
        <!-- <el-table-column prop="ctime" align="center" label="统计日期">
          <template slot-scope="scope">
            {{
              scope.row.ctime
                .split(",")
                .map((date) => date.slice(0, 10))
                .join(",")
            }}
          </template>
        </el-table-column> -->
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button @click="handleGo(scope.row)" size="mini" type="primary"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- <div class="pageUser">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div> -->
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="packGit"
        border
        style="width: 100%"
      >
        <!-- <el-table-column
          label="序号"
          type="index"
          width="70"
          :index="Method1"
          align="center"
        >
        </el-table-column> -->
        <!-- 用户名称用nickname,nickname为空就用name -->
        <el-table-column prop="time" align="center" label="年月">
        </el-table-column>
        <el-table-column prop="name" align="center" label="项目名称">
        </el-table-column>
        <el-table-column prop="count" align="center" label="订单数量">
        </el-table-column>
        <el-table-column prop="amount" align="center" label="订单金额">
        </el-table-column>
      </el-table>
      <!-- <div class="pageUser">
        <el-pagination
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"
          :current-page="page1"
          :page-sizes="[10, 150, 200, 300]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total1"
        >
        </el-pagination>
      </div> -->
    </el-dialog>
  </el-card>
</template>

<script>
import {
  packageCount,
  packageIndex,
  classification,
  goodSort,
} from "../../../../utils/api.js";
import { getJianCaiMoney, getJianCaiMoneyDetail } from "../../../../utils/main";
export default {
  data() {
    return {
      options: [],
      token: sessionStorage.getItem("token"),
      //请求特效
      loading: false,
      //弹窗
      dialogVisible: false,
      form: {
        seal_name: "",
        time: "",
      },
      sum: "",
      time: "",
      //发送请求时间参数
      //展示数据
      tableData: [],

      packGit: [],
      page: 1,
      limit: 10,
      total: 0,
      page1: 1,
      limit1: 10,
      total1: 0,
      name: "",
      type: "",
      order_id: -1,
      time: "",
      cat_id: "",
    };
  },
  methods: {
    //日期
    timeChange(e) {
      // console.log(e);
      // let list = [];
      // e.forEach((item) => {
      //   let date = new Date(item);
      //   let year = date.getFullYear();
      //   let month = date.getMonth() + 1;
      //   let day = date.getDate();
      //   let h = date.getHours();
      //   let min = date.getMinutes();
      //   let s = date.getSeconds();
      //   month = month < 10 ? "0" + month : month;
      //   day = day < 10 ? "0" + day : day;
      //   h = h < 10 ? "0" + h : h;
      //   min = min < 10 ? "0" + min : min;
      //   s = s < 10 ? "0" + s : s;
      //   list.push(
      //     year + "-" + month + "-" + day + " " + h + ":" + min + ":" + s
      //   );
      // });

      // this.time = list[0] + "," + list[1];
      // console.log(this.time);
      this.time = this.form.time;
      if (this.form.time == null) {
        this.time = "";
      }
      this.getList();
    },
    //查询
    onSubmit() {
      this.getList();
    },
    onReset() {
      this.form.time = "";
      this.getList();
    },
    //分页器
    // handleSizeChange(val) {
    //   this.limit = val;
    //   this.getList();
    // },
    // handleCurrentChange(val) {
    //   this.page = val;
    //   this.getList();
    // },
    // handleSizeChange1(val) {
    //   this.limit1 = val;
    //   this.packageCounts(this.order_id);
    //   // this.packageIndexs();
    // },
    // handleCurrentChange1(val) {
    //   this.page1 = val;
    //   this.packageCounts(this.order_id);
    // },
    // 序号排序
    Method(index) {
      if (this.total < this.limit) {
        return this.total - index;
      } else {
        return this.total - (this.page - 1) * this.limit - index;
      }
    },
    Method1(index) {
      if (this.total1 < this.limit1) {
        return this.total1 - index;
      } else {
        return this.total1 - (this.page1 - 1) * this.limit1 - index;
      }
    },
    // 获取商品出售一览表列表
    async getList() {
      this.loading = true;
      let res = await getJianCaiMoney(this.token, this.form.time);
      if (res.data.status) {
        this.tableData = res.data.data || [];
        // this.total = res.data.data.count;
        // console.log(this.total, shouchu);
        this.sum = this.tableData[this.tableData.length - 1].all_amount;
        this.tableData.pop();
        let timer = setTimeout(() => {
          this.loading = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    //获取列表数据
    async packageCounts(name) {
      let res = await getJianCaiMoneyDetail(this.token, name, this.form.time);
      console.log(res);
      if (res.data.status) {
        this.packGit = res.data.data || [];
        // this.tableData = res.data.data.data || [];
        // this.packGit.forEach((item) => {
        //   item.allprice = item.nums * item.price;
        // });
        // this.total1 = res.data.data.count;
        // // console.log(this.total, shouchu);
        // let timer = setTimeout(() => {
        //   this.loading = false;
        //   clearTimeout(timer);
        // }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    // 点击详情的事件
    async handleGo(row) {
      //   console.log("id", row.goods_id);
      this.dialogVisible = true;
      //   this.order_id = row.name;
      this.packageCounts(row.name);
      return;
      // this.$router.push(`/stn/goodsdetail?goods_id=${row.goods_id}`);
    },
    //关闭弹窗
    handleClose(done) {
      done();
      this.page1 = 1;
    },
  },
  mounted() {
    // this.sdhadj();
    this.getList();
    // this.getSelect();
  },
};
</script>

<style scoped>
.sumBox {
  display: flex;
  justify-content: flex-end;
  font-size: 18px;
  color: rgba(249, 100, 34, 1);
  margin-bottom: 10px;
  margin-right: 10px;
}
</style>